package com.shchuangzhi.smartguard.core;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by j_hu on 5/5/17.
 */

public class JobManager {
    private static final HashMap<Integer, Job> jobs = new HashMap<>();

    public static void add(Job job) {
        jobs.put(job.getName(), job);
    }

    public static void remove(int jobName) {
        jobs.remove(jobName);
    }

    public static Job get(int jobName) {
        return jobs.get(jobName);
    }

    public static void startAll() {
        Iterator<Map.Entry<Integer, Job>> iterator = jobs.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry<Integer, Job> entry = iterator.next();
            entry.getValue().start();
        }
    }

    public static void suspendAll() {
        Iterator<Map.Entry<Integer, Job>> iterator = jobs.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry<Integer, Job> entry = iterator.next();
            entry.getValue().suspend();
        }
    }

    public static void resumeAll() {
        Iterator<Map.Entry<Integer, Job>> iterator = jobs.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry<Integer, Job> entry = iterator.next();
            entry.getValue().resume();
        }
    }
}
